﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:localUI="clr-namespace:River.Folderize.UI">

  <ControlTemplate x:Key="ImageToggleTemplate" TargetType="{x:Type localUI:ImageToggle}">
    <Grid x:Name="Grid">
      <Border
        x:Name="Background"
        Background="{TemplateBinding Background}"
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}">
        <Image
          x:Name="ButtonImage"
          Source="{Binding UncheckedImage, RelativeSource={RelativeSource TemplatedParent}}"
          Height="{Binding ImageSize, RelativeSource={RelativeSource TemplatedParent}}"
          Width="{Binding ImageSize, RelativeSource={RelativeSource TemplatedParent}}"
          ToolTip="{TemplateBinding ToolTip}"
          RenderOptions.BitmapScalingMode="NearestNeighbor" />
      </Border>
    </Grid>
    <ControlTemplate.Triggers>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="True" />
          <Condition Property="IsMouseOver" Value="True" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter TargetName="ButtonImage" Property="Source" Value="{Binding CheckedHoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="True" />
          <Condition Property="IsMouseOver" Value="False" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter TargetName="ButtonImage" Property="Source" Value="{Binding CheckedImage, RelativeSource={RelativeSource TemplatedParent}}" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="False" />
          <Condition Property="IsMouseOver" Value="True" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter TargetName="ButtonImage" Property="Source" Value="{Binding UncheckedHoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="True" />
          <Condition Property="IsEnabled" Value="False" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter TargetName="ButtonImage" Property="Source" Value="{Binding CheckedDisabledImage, RelativeSource={RelativeSource TemplatedParent}}" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="False" />
          <Condition Property="IsEnabled" Value="False" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter TargetName="ButtonImage" Property="Source" Value="{Binding UncheckedDisabledImage, RelativeSource={RelativeSource TemplatedParent}}" />
        </MultiTrigger.Setters>
      </MultiTrigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <Style TargetType="{x:Type localUI:ImageToggle}" BasedOn="{x:Null}">
    <Setter Property="Padding" Value="0" />
    <Setter Property="Margin" Value="5" />
    <Setter Property="ImageSize" Value="16" />
    <Setter Property="Width" Value="16" />
    <Setter Property="Height" Value="16" />
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="Template" Value="{StaticResource ImageToggleTemplate}" />
  </Style>

</ResourceDictionary>
